package com.project.slsx.adapter;

import android.widget.LinearLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.project.slsx.R;
import com.project.slsx.bean.GoodsBean;

import java.util.ArrayList;

public class ShopCartAdapter extends BaseQuickAdapter<GoodsBean, BaseViewHolder> {
    private ArrayList<Boolean> selected = new ArrayList<>();

    public ArrayList<Boolean> getSelected() {
        return selected;
    }

    public void setSelected(ArrayList<Boolean> selected) {
        this.selected = selected;
    }

    public ShopCartAdapter(int layoutResId) {
        super(layoutResId);
    }

    @Override
    protected void convert(BaseViewHolder holder, GoodsBean item) {
        int discount = item.getDiscount();
        holder.setText(R.id.tv_shopcart_name, item.getTitle());
        holder.setText(R.id.tv_shopcart_unit_price, item.getPrice() + "");
        holder.setText(R.id.tv_shopcart_num, "X" + item.getNumber());
        holder.setText(R.id.tv_shopcart_total_price, discount == 0 ? "0" : item.getNumber() * item.getPrice() + "");
        LinearLayout llRootView = holder.getView(R.id.ll_item_shop_cart);
        llRootView.setSelected(selected.get(holder.getLayoutPosition()));

    }

    public void setSelectedItem(ArrayList<Boolean> selected) {
        this.selected = selected;
        notifyDataSetChanged();
    }
}
